package string;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "123abc";
        String s2 = "123abc";
        String s3 = "123abc";
        System.out.println(s1 == s2);//true
        System.out.println(s1 == s3);//true

        String s4 = new String("123abc");
        System.out.println(s1 == s4);//false,保存的是地址，新建对象新建地址，所以地址不同为false

        s1+="!";
        System.out.println(s1==s2);//false
        String s = "123";
        String s5 = s+"abc";
        System.out.println(s5==s2);//false
        String s6 = "123"+"abc";//触发预计算特性
        System.out.println(s6==s2);//true

        String s7 = "123abc";
        String s8 = new String("123abc");
        System.out.println(s7==s8);//false，比较地址
        System.out.println(s7.equals(s8));//true，比较内容
    }
}
